{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"contentcontainer med left\" style=\"margin-left: -50px;\">\n",
    "    <dl class=\"dl-horizontal\">\n",
    "      <dt>Title</dt> <dd> BoundsX stream example</dd>\n",
    "      <dt>Description</dt> <dd>A linked streams example demonstrating how to use BoundsX streams. </dd>\n",
    "      <dt>Backends</dt> <dd> Bokeh</dd>\n",
    "      <dt>Tags</dt> <dd> streams, linked, interactive</dd>\n",
    "    </dl>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import holoviews as hv\n",
    "from holoviews import streams\n",
    "hv.extension('bokeh')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%opts Curve[tools=['xbox_select']]\n",
    "\n",
    "n=200\n",
    "xs = np.linspace(0, 1, n)\n",
    "ys = np.cumsum(np.random.randn(n))\n",
    "df = pd.DataFrame({'x': xs, 'y': ys})\n",
    "curve = hv.Curve(df)\n",
    "\n",
    "def make_from_boundsx(boundsx):\n",
    "    sub = df.set_index('x').loc[boundsx[0]:boundsx[1]]\n",
    "    return hv.Table(sub.describe().reset_index().values, kdims=['stat'], vdims=['value'])\n",
    "\n",
    "curve + hv.DynamicMap(make_from_boundsx, streams=[streams.BoundsX(source=curve, boundsx=(0,0))])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center><img src=\"http://assets.holoviews.org/gifs/examples/streams/bokeh/boundsx_selection.gif\"></center>"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
